;// 锁屏消息操作公共逻辑
(function($, undefined) {
})(jQuery);

;
(function($, undefined) {
	// 新建校验
	$(function() {
		var $form = $('#form-add');
		var rules = {
			errorClass : 'ota-error', // 取消自带样式，使用效果更好的layer的tips提示
			focusInvalid : false,
			focusCleanup : true,
			submitHandler : function(form) { // 表单提交句柄,为一回调函数，带一个参数：form
				$(form).ajaxSubmit({
					dataType : 'json',
					success : function(data, statusText, xhr, $form) {
						$.jsonResult(data);
					},
					error : function(xhr, textStatus, errorThrown) {
						console.log('submit error: ' + errorThrown);
						$.jsonResult({
							code : '2'
						});
					}
				});
				return false;
			},
			unhighlight : function(element, errorClass, validClass) {
				$.validateTip(false, element);
			},
			errorPlacement : function(error, element) {
				$.validateTip(true, element, $(error).text());
			},
			ignore : "",
			messages : {
				password2 : {
					equalTo : '两次输入不相同'
				}
			}
		};
		if ($('input[name=id]').val()) {
			rules['rules'] = {
				username : {
					required : true,
					maxlength : 255
				},
				password : {
					maxlength : 255
				},
				password2 : {
					equalTo : '#password'
				},
				checkedRoles : {
					required : true
				}
			};
		} else {
			rules['rules'] = {
				username : {
					required : true,
					maxlength : 255
				},
				password : {
					required : true,
					maxlength : 255
				},
				password2 : {
					required : true,
					equalTo : '#password'
				},
				checkedRoles : {
					required : true
				}
			};
		}
		var validate = $('#form-add').validate(rules);
		$form.on('valid', function(e, data) {
			validate.settings.unhighlight.call(validate, data['el'], validate.settings.errorClass, validate.settings.validClass);
		});
	});
})(jQuery);